/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;




/**
 *
 * @author severinefratani
 */
class DotParser extends StreamTokenizer{

	/** HERITED FROM StreamTokenizer
    static final int TT_WORD = -3;
    static final int TT_NUMBER = -2;
    static final int TT_EOF = -1;

    int ttype;
          After a call to the next method, this field contains the type of the token just read.
    double nval;
          If the current token is a number, (i.e., if ttype == TT_LABEL or, ttype== TT_NUMBER)
          this field contains the value of that number.
    String sval;
          If the current token is a word token, (i.e., if ttype == TT_WORD or ttype=TT_FLOW)
          this field contains a string giving the characters of the word token.
	 **/

	public String toString(){
		String s = new String();
		if (this.ttype==TT_NUMBER)
			s=s+  this.nval ;
		else if (this.ttype==TT_EOF)
			s=s+ " EOF ";
		else s=s+ "unexpected lexem  "+ "'" + (char) this.ttype + "'";
		return s;
	}


	DotParser(String fileName) throws FileNotFoundException{
		super(new FileReader(fileName));
		this.parseNumbers();
		this.ordinaryChar((int)'/');
	}





	int next() throws IOException, DotException{
		this.nextToken();
		if( this.ttype==TT_NUMBER || this.ttype==TT_EOF);

		return this.ttype;
	}
}



class DotException extends Exception{
	private static final long serialVersionUID = -1415527266178177223L;
	DotParser p;
	String expected;
	
	

	public DotException(DotParser p){
		this.p=p;
	}
	
	
	/**
	 * @param p 
	 * @param expected cha�?ne attendue
	 */
	public DotException(DotParser p, String expected){
		this.p=p;
		this.expected = expected;
	}
	
	public String toString(){
		String s = new String("Parse error line "+ p.lineno() + "\n");
		s = s + "unexpected ' " + p + "' \n";
		if (!(expected==null || expected == "")) 
			s = s + expected + " expected ";
		return s;
	}
}         



